	var id = GetQueryString("id");
	var vm = new Vue({
    	  el: '#app',
    	  data: {
			  sourceUser:{}
    	  },
    	  methods: {
			  getUser: function(id){
				  var url = baseURL + "sys/sourceUser/info/" + id;
				  $.get(url, function(data){
				  	  data.sourceUser.id = id;
					  vm.sourceUser = data.sourceUser;
				  });
			  },
    	      saveOrUpdate: function () {
    	    	  var url = "sys/sourceUser/updateInfo";
    				$.loadAjax({
    					type: "POST",
    				    url: baseURL + url,
    	                contentType: "application/json",
    				    data: JSON.stringify(vm.sourceUser),
    				    success: function(r){
    				    	if(r.code === 0){
    				    		layer.alert('提交成功', function(index){
    				    			backToTable();
    				    			layer.close(index);
    							});
    						}else{
    							layer.alert(r.msg);
    						}
    					}
    				});
    	      }
    	  },
    	  mounted:function(){
    		// id 存在则为编辑
		  	if (id != null && id.length > 0) {
		  		// 显示加载中提示
		  		this.getUser(id);
		  	}
    	  }
    });
	
	//表单验证
	$(function() {

        $("#editForm").validate({
            rules: {
				userName: "required",
				idNumber: "required"
            },
            messages: {
            	userName: "请输入姓名名",
				idNumber: "请输入身份证号码",
            },
            submitHandler : function(form) {  //验证通过后的执行方法
                //当前的form通过ajax方式提交
                vm.saveOrUpdate();
            },
            /* 重写错误显示消息方法,以tips方式弹出错误消息 */   
            showErrors: function(errorMap, errorList) {   
            	var msg = "";   
                $.each( errorList, function(i,v){   
                  msg = (v.message+"\r\n");   
                  if(msg!="") layer.tips(msg, "#"+v.element.id, { tips:2, tipsMore: true });   
                });   
            },   
            /* 提示失去焦点时不验证 */    
            onfocusout: false 
        });
    });
    
        
        